package com.plian.system.service.sys.bigdata.Investment;


import com.plian.Tools.UuidUtil;
import com.plian.Tools.pagedata.PageData;
import com.plian.system.entity.pm.propertyinformation.PropertyTime;
import com.plian.system.mapper.fr.bigdata.InvestmentinfoMapper;
import com.plian.system.service.im.IBaseInvestmentPlanService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

/**
 * @author huzb
 * @create 2020-10-23 9:02
 */

@Service
@AllArgsConstructor
public class InvestmentOutForService {
    InvestmentinfoMapper investmentinfoMapper;

    IBaseInvestmentPlanService investmentPlanService;

    public List<PageData> insertBasicInfo(PropertyTime propertyTime){
        String op = "0";
        List<PageData> list = new ArrayList<>();
        List<PageData> listByDateRange = investmentPlanService.findInvestListByDateCreate(propertyTime);
        addList(listByDateRange,list,op);
        return list;
    }

//    @DS("slave_1")
    public void insertInvestmentInfo(List<PageData> list){
        for (PageData pd :list){
            investmentinfoMapper.insertInvestmentInfo(pd);
        }
    }

    public static void addList(List<PageData> listByDateRange,List<PageData> list,String op){
        for (PageData pd : listByDateRange){
            Set set = pd.keySet();
            Iterator iterator = set.iterator();
            while (iterator.hasNext()){
                String key = (String)iterator.next();
                String value = pd.getString(key);
                if (value == null){
                    pd.put(key,"");
                }else {
                    pd.put(key,value);
                }
            }
            pd.put("op",op);
            pd.put("id", UuidUtil.get32UUID());
            list.add(pd);
        }
    }

}
